package sust.cse.ruhul.jobs1;

import java.util.Calendar;
import java.util.Date;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ServiceReportScreen extends Activity
{
	private static final int	DATE_DIALOG_ID	= 999;
	// Model
	private int					year;
	private int					month;
	private int					day;

	// View
	private RelativeLayout		panel7;
	private Button				btnSendReportForReview;
	private TextView			dateKey, dateValue, sendValue;
	private EditText			issuesEditText;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.service_report_screen);
		issuesEditText=(EditText)findViewById(R.id.issues_edittext);
		panel7 = (RelativeLayout) findViewById(R.id.panel7);
		sendValue = (TextView) findViewById(R.id.send_value);
		btnSendReportForReview = (Button) findViewById(R.id.btn_send_report_for_review);
		dateKey = (TextView) findViewById(R.id.date_key);
		dateValue = (TextView) findViewById(R.id.date_value);
		// Get current date by calender

		final Calendar c = Calendar.getInstance();
		year = c.get(Calendar.YEAR);
		month = c.get(Calendar.MONTH);
		day = c.get(Calendar.DAY_OF_MONTH);

		// FragmentManager fgm=get
		dateKey.setOnClickListener(new OnClickListener()
		{

			@Override
			public void onClick(View v)
			{

				// On button click show datepicker dialog
				showDialog(DATE_DIALOG_ID);

				// DialogFragment newFragment = new DatePickerFragment();
				// newFragment.show(getSupportFragmentManager(), "datePicker");

			}

		});

		btnSendReportForReview.setOnClickListener(new OnClickListener()
		{

			@Override
			public void onClick(View v)
			{
				sendValue.setText(new Date().toString());
				panel7.setVisibility(View.VISIBLE);

			}
		});
	}

	@Override
	protected Dialog onCreateDialog(int id)
	{
		switch (id)
		{
		case DATE_DIALOG_ID:

			// open datepicker dialog.
			// set date picker for current date
			// add pickerListener listner to date picker
			return new DatePickerDialog(this, pickerListener, year, month, day);
		}
		return null;
	}

	private DatePickerDialog.OnDateSetListener	pickerListener	= new DatePickerDialog.OnDateSetListener()
																{

																	// when
																	// dialog
																	// box is
																	// closed,
																	// below
																	// method
																	// will be
																	// called.
																	@Override
																	public void onDateSet(
																			DatePicker view,
																			int selectedYear,
																			int selectedMonth,
																			int selectedDay)
																	{

																		year = selectedYear;
																		month = selectedMonth;
																		day = selectedDay;

																		// Show
																		// selected
																		// date
																		dateValue
																				.setText(new StringBuilder()
																						.append(month + 1)
																						.append("-")
																						.append(day)
																						.append("-")
																						.append(year)
																						.append(" "));

																	}
																};

	public static class DatePickerFragment extends DialogFragment implements
			DatePickerDialog.OnDateSetListener
	{

		@Override
		public Dialog onCreateDialog(Bundle savedInstanceState)
		{
			// Use the current date as the default date in the picker
			final Calendar c = Calendar.getInstance();
			int year = c.get(Calendar.YEAR);
			int month = c.get(Calendar.MONTH);
			int day = c.get(Calendar.DAY_OF_MONTH);

			// Create a new instance of DatePickerDialog and return it
			return new DatePickerDialog(getActivity(), this, year, month, day);
		}

		public void onDateSet(DatePicker view, int year, int month, int day)
		{
			// Do something with the date chosen by the user
		}
	}
}